package com.net.io.netty.serialize.jdk;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @author zhangtengfei
 * @date 2022/2/16 16:45
 */
public class TestUserInfo {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        UserInfo userInfo = new UserInfo();
        userInfo.buildUserID(100).buildUserName("Welcome to Netty");
        /*
         * -----------------------------------------------------------------------------------
         * ----------------------------------- jdk序列化耗时 -----------------------------------
         * -----------------------------------------------------------------------------------
         */
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(bos);
        os.writeObject(userInfo);
        os.flush();
        os.close();
        byte[] b = bos.toByteArray();
        // The jdk serializable length is : 124
        System.out.println("The jdk serializable length is : " + b.length);
        bos.close();
        System.out.println("--------------------------------------------------------------------------");
        /*
         * -----------------------------------------------------------------------------------
         * ----------------------------- byte array serializable -----------------------------
         * -----------------------------------------------------------------------------------
         */
        // The byte array serializable length is : 24
        System.out.println("The byte array serializable length is : " + userInfo.codeC().length);
    }

}
